# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=eigen
pkgbase=mingw-w64-${_realname}3
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}3")
pkgver=3.2.8
pkgrel=1
pkgdesc="Lightweight C++ template library for vector and matrix math (mingw-w64)"
arch=('any')
url='http://eigen.tuxfamily.org'
license=('MPL2')
options=('strip' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-fftw"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-mpfr"
             #"${MINGW_PACKAGE_PREFIX}-qt4"
             )
source=(${_realname}-${pkgver}.tar.bz2::"https://bitbucket.org/eigen/eigen/get/${pkgver}.tar.bz2"
        'eigen-3.1.2_osversion.patch'
        'eigen-3.2_gcc58087.patch'
        'TryRunResults.cmake'
        'eigen-pkgconfig.patch')
sha256sums=('722a63d672b70f39c271c5e2a4a43ba14d12015674331790414fcb167c357e55'
            '74e49f0a5d42db617ce12f8016e58191f65b8f112c9de6a650d7e3443ee0a316'
            '24adde9c7766f9ea7e6546f5915471d3885653d50790729249491942ab51dea1'
            '9ebec4761a7de150ade4b421407a4b5148065416fa8010ecfbdd404bab68f899'
            '0166749c49585a64c99513c16bf1fcd6130252e9273ad9d0685eb8439ba47608')

prepare() {
  cd "${srcdir}"/eigen-eigen-*

  patch -Np2 -i "${srcdir}/eigen-3.1.2_osversion.patch"
  patch -Np1 -i "${srcdir}/eigen-3.2_gcc58087.patch"
  patch -Np1 -i "${srcdir}/eigen-pkgconfig.patch"
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DEIGEN_BUILD_PKGCONFIG=ON \
    -DFFTW_USE_STATIC_LIBS=ON \
    -DFFTW_ROOT=${MINGW_PREFIX} \
    -C "${srcdir}"/TryRunResults.cmake \
    ../eigen-eigen-*

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
